var e = getApp(), a = require("../../model/awconfig.js"), o = require("../../utils/util.js");

Page({
    data: {
        videoId:e.globalData.videoId,
        adKeyHome: e.globalData.adKeyHome,
        adKeyDYDownload: e.globalData.adKeyDYDownload,
        adKeyDYVideoInfo: e.globalData.adKeyDYVideoInfo,
        adKeyDYMusic: e.globalData.adKeyDYMusic,
        adKeyUserInifo: e.globalData.adKeyUserInifo,
        adKeyKSDownload: e.globalData.adKeyKSDownload,
        adKeyAlert: e.globalData.adKeyAlert,
        adKeyMore: e.globalData.adKeyMore,
        ad_mode_banner_3: e.globalData.ad_mode_banner_3,
        ad_mode_hover1: e.globalData.ad_mode_hover1,
        adKeyWater: e.globalData.adKeyWater,
        adRewardedVideo1: e.globalData.adRewardedVideo1,
        showPoem: 0,
        openCustomerMore: 0,
        customerMoreTitle: "客服",
        tutorialMoreTitle: "使用教程",
        adMoreImage: "../../images/ad_normal.jpg",
        adMoreTitle: "",
        adMoreAppID: "",
        adMorePath: "",
        openMenuRewardedVideoAd: 0,
        showTimeLine: 1,
        openShareMore: 0,
        shareGroupText: "推荐小程序到微信群",
        shareTimeLineText: "获取推荐的二维码图",
        adBannerTypeMore: 0,
        list_tools: [ {
            title: "使用教程",
            name: "icon",
            color: "cyan",
            icon: "icon",
            app_id: "wx4ed902e153b35e79",
            url: "/pages/tutorialImages/tutorialImages"
        }, {
            title: "常见问题",
            name: "layout",
            color: "cyan",
            icon: "newsfill",
            url: "/pages/question/question"
        } ],
        list_more: [],
        list_more_r: [],
        applist:[
            {app_id:'wx5f86be04ccb69a16',icon:'https://img-blog.csdnimg.cn/4abe86982b6a4dcfb7fe30e9fc82e4da.jpg',title:'口罩头像',url:'',isShow:true},
            {app_id:'wx6820760b1be48361',icon:'https://beta.gtimg.com/rdmimg/aiwx/img/41989edd-7082-4567-9fd0-cd54802dd764.jpg',title:'图片合成',url:'',isShow:true},
            {app_id:'wxa462737609b95a2c',icon:'https://beta.gtimg.com/rdmimg/aiwx/img/41989edd-7082-4567-9fd0-cd54802dd764.jpg',title:'动图gif',url:'',isShow:true},
            {app_id:'',icon:'https://beta.gtimg.com/rdmimg/aiwx/img/41989edd-7082-4567-9fd0-cd54802dd764.jpg',title:'免费api接口列表',url:'/packageA/pages/article?type=api',isShow:false},
            {app_id:'',icon:'https://beta.gtimg.com/rdmimg/aiwx/img/41989edd-7082-4567-9fd0-cd54802dd764.jpg',title:'免费源码列表',url:'/packageA/pages/article?type=article',isShow:false},
        ]
    },
    onLoad: function(e) {
        let that = this
        wx.request({
            url: 'https://guanhe.work/xiaochengxu/getAppAd',
            data:{},
            success(res){
                wx.hideLoading({
                    success: (res) => {},
                  })
                if(res.data.code == 200){
                    if(res.data.results[0].tuijiantype){
                        that.setData({
                            ['applist[3].isShow']:true,
                            ['applist[4].isShow']:true,
                        })
                    }
                } else {
                    that.setData({
                        ['applist[3].isShow']:true,
                        ['applist[4].isShow']:true,
                    })
                }
            },
            fail(e){
                that.setData({
                    ['applist[3].isShow']:true,
                    ['applist[4].isShow']:true,
                })
                wx.hideLoading({
                  success: (res) => {},
                })
            }
        })
        var o = this, t = "/images/logo.jpg";
        "M_KuaiDou." != getApp().globalData.appName && "M_MianFeiShuiYin" != getApp().globalData.appName || (t = "/images/logo_kuaidou.jpg"), 
        "M_PinTu" == getApp().globalData.appName && (t = "/images/logo_pintu.jpg"), o.setData({
            topImageURL: t
        }), a.registerConfigCallback(function() {
            o.awconfigSuccessCallback(1);
        }, function(e) {}), o.awconfigSuccessCallback(0), 1 == o.data.openMenuRewardedVideoAd && o.setupVideoAD();
    },
    awconfigSuccessCallback: function(e) {
        var a = wx.getStorageSync("appConfig"), o = this.data.list_more;
        null != a.list_more && (o = a.list_more);
        var t = this.data.list_more_r;
        null != a.list_more_r && (t = a.list_more_r);
        var r = this.data.showPoem;
        null != a.showPoem && (r = a.showPoem);
        var i = this.data.openCustomerMore;
        null != a.openCustomerMore && (i = a.openCustomerMore);
        var n = this.data.customerMoreTitle;
        null != a.customerMoreTitle && (n = a.customerMoreTitle);
        var d = this.data.tutorialMoreTitle;
        null != a.tutorialMoreTitle && (d = a.tutorialMoreTitle);
        var l = this.data.topImageURL;
        null != a.topImageURL && (l = a.topImageURL);
        var s = this.data.adMoreImage;
        null != a.adMoreImage && (s = a.adMoreImage);
        var u = this.data.adMoreTitle;
        null != a.adMoreTitle && (u = a.adMoreTitle);
        var p = this.data.adMoreAppID;
        null != a.adMoreAppID && (p = a.adMoreAppID);
        var c = this.data.adMorePath;
        null != a.adMorePath && (c = a.adMorePath);
        var m = this.data.openMenuRewardedVideoAd;
        null != a.openMenuRewardedVideoAd && (m = a.openMenuRewardedVideoAd);
        var g = this.data.openShare;
        null != a.openShare && (g = a.openShare);
        var h = this.data.openShareMore;
        null != a.openShareMore && (h = a.openShareMore);
        var T = this.data.shareGroupText;
        null != a.shareGroupText && (T = a.shareGroupText);
        var w = this.data.showTimeLine;
        null != a.showTimeLine && (w = a.showTimeLine);
        var M = this.data.shareTimeLineText;
        null != a.shareTimeLineText && (M = a.shareTimeLineText);
        var f = this.data.adBannerTypeMore;
        null != a.adBannerTypeMore && (f = a.adBannerTypeMore), this.setData({
            list_more: o,
            list_more_r: t,
            showPoem: r,
            openCustomerMore: i,
            customerMoreTitle: n,
            tutorialMoreTitle: d,
            topImageURL: l,
            adMoreImage: s,
            adMoreTitle: u,
            adMoreAppID: p,
            adMorePath: c,
            openMenuRewardedVideoAd: m,
            openShare: g,
            openShareMore: h,
            shareGroupText: T,
            showTimeLine: w,
            shareTimeLineText: M,
            adBannerTypeMore: f
        });
    },
    showRewardedVideoAdTips: function(e) {
        var a = this;
        wx.showModal({
            title: "提示",
            confirmText: e.confirmText,
            cancelText: e.cancelText,
            content: e.adDesc,
            success: function(e) {
                e.confirm ? a.showRewardedVideoAd() : e.cancel && console.log("用户点击取消");
            }
        });
    },
    showRewardedVideoAd: function() {
        var e = this.data.rewardedVideoAd;
        e.show().catch(function(a) {
            e.load().then(function() {
                return e.show();
            });
        });
    },
    setupVideoAD: function() {
        var a = this, t = e.globalData.systemInfo.SDKVersion;
        if (!(o.compareVersion(t, "2.6.0") < 0)) {
            var r = wx.createRewardedVideoAd({
                adUnitId: a.data.adRewardedVideo1
            });
            r.onLoad(function() {
                console.log("广告加载成功"), a.setData({
                    videoADLoaded: !0
                });
            }), r.onError(function(e) {
                console.log("广告加载失败"), console.log(e), a.setData({
                    videoADLoaded: !1
                });
            }), r.onClose(function(e) {
                e && e.isEnded || void 0 === e ? (o.setExpiredTimeStamp("ExpiredTime"), o.setExpiredTimeStamp("DuJiaExpiredTime"), 
                wx.showToast({
                    title: "看广告成功"
                })) : wx.showToast({
                    title: "没有看完广告"
                });
            }), a.setData({
                rewardedVideoAd: r
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    waterMarkTap: function() {
        wx.navigateTo({
            url: "/pages/waterMarkSet/waterMarkSet"
        });
    },
    wordCombineTap: function() {
        wx.navigateTo({
            url: "/pages/wordCombine/wordCombine"
        });
    },
    poemTap: function() {
        wx.navigateTo({
            url: "/pages/poem/poem"
        });
    },
    combineTap: function() {
        wx.chooseImage({
            count: 9,
            success: function(e) {
                var a = e.tempFilePaths, o = JSON.stringify(a);
                wx.navigateTo({
                    url: "/pages/photoCombine/photoCombine?imageUrls=" + o
                });
            }
        });
    },
    tapTutorial: function(e) {
        wx.navigateTo({
            url: "/pages/tutorialImages/tutorialImages"
        });
    },
    clickListAD: function(e) {
        wx.navigateToMiniProgram({
            appId: this.data.adMoreAppID,
            path: this.data.adMorePath,
            extraData: {
                foo: "bar"
            },
            envVersion: "release",
            success: function(e) {}
        });
    },
    clickItem: function(e) {
        var a = e.currentTarget.dataset.index, t = this.data.applist[a];
        if (1 == this.data.openMenuRewardedVideoAd && 1 == t.rewardedUnlock && this.data.videoADLoaded && 0 == o.canMake("DuJiaExpiredTime")) this.showRewardedVideoAdTips(t); else {
            var r = JSON.stringify(t), i = t.app_id, n = e.currentTarget.dataset.url;
            wx.setStorageSync("currentItem", encodeURI(r)), console.log(n), null != i && "" != i ? wx.navigateToMiniProgram({
                appId: i,
                path: n,
                extraData: {
                    foo: "bar"
                },
                envVersion: "release",
                success: function(e) {}
            }) : wx.navigateTo({
                url: n
            });
        }
    },
    toChild: function(e) {
        e.currentTarget.dataset.index;
        var a = e.currentTarget.dataset.url;
        console.log(a), wx.navigateTo({
            url: a
        });
    }
});